package com.gongpingjialoan.adapter.car;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.bean.SelectBean;

import java.util.List;

/**
 * 买车->筛选->GridViewAdapter
 * Created by Administrator on 2015/12/16.
 */
public class CarlistSelectFilterAdapter extends BaseAdapter{
    Context mContext;
    List<SelectBean> list;
    Resources mResources;

    public CarlistSelectFilterAdapter(Context context) {
        this.mContext = context;
        mResources = context.getResources();
    }

    public void setData(List<SelectBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        if (list == null) {
            return null;
        }
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = LayoutInflater.from(mContext).inflate(R.layout.item_filetr, viewGroup, false);
            holder = new ViewHolder();
            holder.radio = (TextView) view.findViewById(R.id.price_one);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.radio.setText(list.get(i).getShow_name());
        if (list.get(i).isCheack()) {
            holder.radio.setBackgroundResource(R.drawable.button_big_bg_normal);
            holder.radio.setTextColor(mResources.getColor(R.color.white));
        }else {
            holder.radio.setBackgroundResource(R.drawable.discount_filter_normal);
            holder.radio.setTextColor(mResources.getColor(R.color.text_details_color));
        }
//        holder.radio.setOnClickListener(new MyOnClick(i));
        return view;
    }
//    class MyOnClick implements View.OnClickListener {
//        int position;
//        public MyOnClick(int position){
//            this.position = position;
//        }
//        @Override
//        public void onClick(View v) {
//            switch (v.getId()) {
//                case R.id.price_one:
//                    for (int i = 0; i < list.size(); i++) {
//                        if (i==position) {
//                            list.get(i).setCheack(true);
////                            ((CarListFilterActivity)mContext).setPrice(i);
//                        }else {
//                            list.get(i).setCheack(false);
//                        }
//                    }
//                    notifyDataSetChanged();
//                    break;
//            }
//        }
//    }

    class ViewHolder{
        TextView radio;
    }
}
